#include "Processbar.h"
#include<string.h>
#include<unistd.h>


/*void Fortest()
{
  printf("this is for test\n");
  printf("this is for test\n");
  printf("this is for test\n");
  printf("this is for test\n");
  printf("this is for test\n");
}*/

#define length 101
#define style '-'
const char* lable="|/-\\";


/*void Procbar()
{
  char bar[length];
  memset(bar,'\0',sizeof(bar));
  int len=strlen(lable);

  int cnt=0;
  while(cnt<=100)
  {
    printf("[%-100s][%3d%%][%c]\r",bar,cnt,lable[cnt%len]);
    fflush(stdout);
    bar[cnt++]=style;
    usleep(20000);
  }
  printf("\n");
}*/


void Procbar(double total,double current)
{
  char bar[length];
  memset(bar,'\0',sizeof(bar));
  int len=strlen(lable);

  int cnt=0;
  double rate=(current*100.0)/total;
  int loop_count=(int)rate;
  while(cnt<=loop_count)
  {
    bar[cnt++]=style;
  }
  printf("[%-100s][%.1lf%%][%c]\r",bar,rate,lable[cnt%len]);
  fflush(stdout);
}
